package com.daohang361.imqq.ui;

import java.awt.Color;
import java.awt.Container;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import com.csu.client.tools.EIMClientConfig;
import com.daohang361.imqq.service.LoginService;
import com.daohang361.imqq.ui.img.Imagecanvas;
import com.daohang361.imqq.ui.trayIcon.EIMTrayIcon;

public class WaitLoginFrame extends BaseFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static WaitLoginFrame instance;
	public static int qqNumber=0;
	
	public static WaitLoginFrame getInstance(){
		if(instance==null){
			instance=new WaitLoginFrame();
		}
		return instance;
	}
	
	
	 /** Creates new form QQWaitLoginFrame */
    private WaitLoginFrame() {
    	super();
        initComponents();
        this.setResizable(false);
		
    }
    
    
    
    public  void changTryIcon(){
    	EIMTrayIcon trayIcon=EIMTrayIcon.getInStance();
    	trayIcon.setFrame(instance);
    	trayIcon.setTrayIconState(EIMClientConfig.LoginingTryIcon_Type);
    	trayIcon.showIcon(EIMClientConfig.LoginingTryIcon_Type);
    }
    
    private void initComponents() {
        Container c= getContentPane();
//        c.setBackground( new Color(214,238,255));
        c.setBackground( new Color(0xE0FFFF));
    	this.setAlwaysOnTop(true);
        quxiao_Button = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        qqLogo_Pane = new javax.swing.JPanel();
        Imagecanvas canvas1=new Imagecanvas("ui/Logining.gif",170,170);
        
        qqLogo_Pane.add(canvas1);
        
        quxiao_Button.setText("\u53d6\u6d88\u767b\u5f55");//取消登录
        quxiao_Button.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                quxiao_ButtonMouseClicked(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel1.setText(""+getQqNumber());//正在登陆
        jLabel2.setFont(new java.awt.Font("宋体", 1, 12));
        jLabel2.setText("正在登陆");//正在登陆
        javax.swing.GroupLayout qqLogo_PaneLayout = new javax.swing.GroupLayout(qqLogo_Pane);
        qqLogo_Pane.setLayout(qqLogo_PaneLayout);
        qqLogo_PaneLayout.setHorizontalGroup(
            qqLogo_PaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 170, Short.MAX_VALUE)
        );
        qqLogo_PaneLayout.setVerticalGroup(
            qqLogo_PaneLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 170, Short.MAX_VALUE)
        );
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

        c.setLayout(layout);

        layout.setHorizontalGroup
        (
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                		
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        )
                        .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                        )
                     .addGroup(
                    		 layout.createSequentialGroup().addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).
                    		 addComponent(quxiao_Button,javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))   
                    
                     .addGroup(layout.createSequentialGroup().addGap(80, 80, 80)//旋转图片
                        .addComponent(qqLogo_Pane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        
                         )
                .addContainerGap(36, Short.MAX_VALUE)
                      )
        );
        
        
        layout.setVerticalGroup
        (
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(53, 53, 53)
                .addComponent(qqLogo_Pane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        
                         )
                  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addComponent(quxiao_Button)
                .addGap(73, 73, 73)
               
                .addContainerGap(174, Short.MAX_VALUE)
                     )
        );
        
        addWindowListener(new WindowAdapter(){
	    	public void windowClosing(WindowEvent e){
	    	   	setVisible(false);
	    	   	EIMLoginFrame loginFrame=EIMLoginFrame.getInstance();
	    	   	loginFrame.changTryIcon();
	        	BaseFrame.centerWindow(loginFrame);
	        	loginFrame.setVisible(true);
	    	}}); 
	
	    addWindowListener(new WindowAdapter(){
	    	public void windowIconified(WindowEvent   e){
	    		
	    		}}); 
	    
        pack();
    }// </editor-fold>                        

    /**
     * 取消按钮事件
     * @param evt
     */
    private void quxiao_ButtonMouseClicked(java.awt.event.MouseEvent evt) { 
    	this.setVisible(false);
    	EIMLoginFrame loginFrame=EIMLoginFrame.getInstance();
    	BaseFrame.centerWindow(loginFrame);
    	loginFrame.changTryIcon();
    	loginFrame.setVisible(true);
    }                                          
    
    
    public static void setQqNumber(int qqNumber) {
		WaitLoginFrame.qqNumber = qqNumber;
	}


	public static int getQqNumber() {
		return qqNumber;
	}

	// 变量声明 - 不进行修改                     
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel progress_Panel;
    private javax.swing.JPanel qqLogo_Pane;
    private javax.swing.JButton quxiao_Button;
    // 变量声明结束                   

	public static boolean getLoginState() {
		
		try {
			System.out.println("LoginState qqNumber:"+qqNumber);
			return LoginService.getLoginState(qqNumber);
		} catch (Exception e) {
			return false;
		}
	}
}
